package calendar.commands.events;

import calendar.commands.ClientCommand;
import calendar.model.CalendarModel;
import com.google.api.client.googleapis.batch.BatchRequest;
import com.google.api.client.googleapis.batch.json.JsonBatchCallback;
import com.google.api.client.googleapis.json.GoogleJsonError;
import com.google.api.client.http.HttpHeaders;
import com.google.api.services.calendar.model.Calendar;

public class DeleteCalendarUsingBatch extends ClientCommand {
    public DeleteCalendarUsingBatch(com.google.api.services.calendar.Calendar client) {
        super(client);
    }

    @Override
    protected void protectedExecute() throws Exception {
        BatchRequest batch = client.batch();
        for (Calendar calendar : CalendarModel.addedCalendarsUsingBatch) {
            client.calendars().delete(calendar.getId()).queue(batch, new JsonBatchCallback<Void>() {

                @Override
                public void onSuccess(Void content, HttpHeaders responseHeaders) {
                    System.out.println("Delete is successful!");
                }

                @Override
                public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
                    System.out.println("Error Message: " + e.getMessage());
                }
            });
        }

        batch.execute();
    }
}
